package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.UserDTO;
import com.sky.entity.User;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户信息
     * @param nickname
     * @return
     */
    @Select("select * from user where nickname = #{nickname}")
    User selectByUsername(String nickname);

    /**
     * 插入用户信息
     * @param user
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into user (nickname, email,avatar, create_time, update_time) " +
            "values (#{nickname}, #{email},#{avatar}, #{createTime}, #{updateTime})")
    void insertUser(User user);

    /**
     * 根据昵称查询用户信息
     * @param nickname
     * @return
     */
    @Select("select * from user where nickname = #{nickname}")
    User selectByNickname(String nickname);

    /**
     * 插入新用户
     * @param userDTO
     */
    void insertNewUser(UserDTO userDTO);

    /**
     * 根据用户id查询用户昵称
     * @param currentId
     * @return
     */
    @Select("select nickname from user where id = #{currentId}")
    String findUserNickname(Long currentId);
}
